//void, Obj This
Building this;
point ptDummy; Obj objDummy;
int max_pop;
str strCmd;

Sleep(16080+rand(GetConst("RandTimeStart"))+GetConst("AddTimeStart"));

this = This.AsBuilding();

if (!.IsValid) return;
//pr("auto call dziala");

while(.IsValid){
	if(IsAIPlayer(.player)){
		while(.IsValid) {
			Sleep(60000);
			if(!IsAIPlayer(.player)) break;
		}
		
	} else {
		if(EnvReadString(.settlement, "auto_call_peasants") == "yes"){
			
			max_pop = .settlement.max_population;
			if(.settlement.population >= max_pop){          
				strCmd = "trainpeasant"+.settlement.GetCentralBuilding.raceStrPrefLow; 
				.ExecCmd(strCmd, ptDummy, objDummy, false);
				Sleep(12000);

			}
		}
	}
    Sleep(4000);
}